# coding:utf-8
import time
import os
from appium import webdriver
from time import sleep
PATH = lambda p:os.path.abspath(os.path.join(os.path.dirname(__file__),p))
def init_case(self):
    '''登录后弹框关闭处理逻辑
    1、优先判断是否存在升级弹框，如果有选择暂不升级
    2、判断是否存在年级弹框，如果有选择一年级并确定
    3、判断是否存在定向宝箱，如果有点击前去看看，再点击暂不使用
    4、判断是否有布克漫画提示框，如果有就点击“关闭
    5、判断是否有校榜月榜排名框，如果有就点击“关闭
    6、判断是否有签到弹框，如果有，点击back键关闭
    '''
    print "Initialize"
    try:
        time.sleep(2)
        if self.isElementExist("com.knowbox.rc.student.pk:id/tv_title"):
            self.driver.find_element_by_id("com.knowbox.rc.student.pk:id/btn_cancel").click()
        if self.isElementExist("com.knowbox.rc.student.pk :id/btn_ok"):
            self.driver.find_element_by_id("com.knowbox.rc.student.pk:id/tv_grade_1").click()
            time.sleep(2)
            self.driver.find_element_by_id("com.knowbox.rc.student.pk:id/btn_ok ").click()
            time.sleep(2)
        if self.isElementExist("com.knowbox.rc.student.pk:id/btn_ok"):
            self.driver.find_element_by_id("com.knowbox.rc.student.pk:id/btn_ok ").click()
            time.sleep(2)
            self.driver.find_element_by_id("com.knowbox.rc.student.pk:id/btn_cancel").click()
        if self.isElementExist("com.knowbox.rc.student.pk:id/go_to_see"):
            self.driver.find_element_by_id("com.knowbox.rc.student.pk:id/close_block_des_dialog_btn").click()
        if self.isElementExist("com.knowbox.rc.student.pk:id/dialog_rank_img"):
            self.driver.find_element_by_id("com.knowbox.rc.student.pk:id/close_dialog_btn").click()
        if self.isElementExist("com.knowbox.rc.student.pk:id/iv_attendance_sign_in"):
            self.driver.keyevent(4)
            time.sleep(2)
    except Exception, ex:
        pass
# def setUp(self):
#     desired_caps = {}
#     desired_caps['platformName'] = 'Android'
#     desired_caps['platformVersion'] = '4.4.4'
#     desired_caps['deviceName'] = 'Galaxy E7'
#     desired_caps['appPackage'] = 'com.knowbox.rc.student.pk'
#     desired_caps['appActivity'] = 'com.knowbox.rc.MainActivity'
#     desired_caps['app'] = PATH('D:\\PycharmProjects\\knowbox1\\apps\\AndroidRCStudent_327.apk')
#     desired_caps['unicodeKeyboard'] = True
#     desired_caps['noReset'] = True
#     self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
# def tearDown(self):
#     self.driver.quit()
#     print "end..."
